home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / editors / pur_c_vi.zoo / window.c < prev   
Encoding:
C/C++ Source or Header  |  1992-08-13  |  2.5 KB  |  186 lines

  1. /*
  2.  * STevie - ST editor for VI enthusiasts.    ...Tim Thompson...twitch!tjt...
  3.  * vt100 mode + reading of LINES/COLUMNS for ATARI added by Kees Lemmens
  4.  */
  5.  
  6. #include "stevie.h"
  7. #include <stdio.h>
  8.  
  9. #ifdef ATARI
  10. # include <osbind.h>
  11. # define EscSeq(x) Cconout('\033');Cconout(x);
  12. # define VT52        52
  13. # define VT100        100
  14.   int Termtype;
  15. #endif
  16. #ifdef UNIXPC
  17. # include <sys/window.h>
  18. #endif
  19. #ifdef TCAP
  20. # include <curses.h>
  21. #endif
  22.  
  23. windinit()
  24. {
  25. #ifdef ATARI
  26.     char *getenv();
  27.     char *p = getenv("TERM");
  28.     char *c = getenv("COLUMNS");
  29.     char *l = getenv("LINES");
  30.     
  31.     Termtype=VT52;
  32.     Columns=80;
  33.     Rows=25;
  34.  
  35.     if ( p != NULL )
  36.         if (strncmp(p,"vt100",5) == 0)
  37.             Termtype = VT100;
  38.     if ( c != NULL )
  39.         Columns = atoi(c);
  40.     if ( l != NULL )
  41.         Rows = atoi(l);
  42. #endif
  43. #ifdef UNIXPC
  44.         struct uwdata uw;
  45.         
  46.     winit();
  47.     if ( ioctl(0,WIOCGETD,&uw) == -1
  48.       && ioctl(1,WIOCGETD,&uw) == -1
  49.       && ioctl(2,WIOCGETD,&uw) == -1 ) {
  50.         fprintf(stderr,"*** ERROR *** Not a window!\n");
  51.         windexit(1);
  52.     }
  53.     Columns = uw.uw_width / uw.uw_hs;
  54.     Rows = uw.uw_height / uw.uw_vs;
  55.     cbreak();
  56.     nonl();
  57.     noecho();
  58. #endif
  59. #ifdef TCAP
  60.     char *getenv();
  61.     char *p = getenv("TERM");
  62.  
  63.     initscr();
  64.     Columns = 80;
  65.     if ( strncmp(p,"vt52",4)==0 )
  66.         Rows = 25;
  67.     else
  68.         Rows = 24;
  69.     cbreak();
  70.     nonl();
  71.     noecho();
  72. #endif
  73. }
  74.  
  75. windgoto(r,c)
  76. int r,c;
  77. {
  78. #ifdef UNIXPC
  79.     printf("\033[%d;%dH",r+1,c+1);
  80. #endif
  81. #ifdef ATARI
  82.     char *itoa();
  83.     
  84.     if (Termtype == VT100)
  85.     {    printf("\033[%d;%dH",r+1,c+1);
  86.     }
  87.     else
  88.     {    EscSeq('Y');
  89.         Cconout(r+040);
  90.         Cconout(c+040);
  91.     }
  92. #endif
  93. #ifdef TCAP
  94.     move(r,c);
  95. #endif
  96. }
  97.  
  98. windexit(r)
  99. int r;
  100. {
  101. #ifdef UNIXPC
  102.     nocbreak();
  103.     nl();
  104.     echo();
  105.     wexit();
  106. #endif
  107. #ifdef TCAP
  108.     nocbreak();
  109.     nl();
  110.     echo();
  111.     endwin();
  112. #endif
  113.     exit(r);
  114. }
  115.  
  116. windclear()
  117. {
  118. #ifdef UNIXPC
  119.     printf("\033[H\033[J");
  120. #endif
  121. #ifdef ATARI
  122.     if (Termtype == VT100)
  123.         Cconws("\033[H\033[J");
  124.     else
  125.         Cconws("\033H\033J");
  126. #endif
  127. #ifdef TCAP
  128.     clear();
  129.     refresh();
  130. #endif
  131. }
  132.  
  133. windgetc()
  134. {
  135. #ifdef ATARI
  136.     return(Cnecin());
  137. #else
  138.     return(getchar());
  139. #endif
  140. }
  141.  
  142. windstr(s)
  143. char *s;
  144. {
  145. #ifdef ATARI
  146.     Cconws(s);
  147. #endif
  148. #ifdef UNIXPC
  149.     printf("%s",s);
  150. #endif
  151. #ifdef TCAP
  152.     addstr(s);
  153.     refresh();
  154. #endif
  155. }
  156.  
  157. windputc(c)
  158. int c;
  159. {
  160. #ifdef ATARI
  161.     Cconout(c);
  162. #endif
  163. #ifdef UNIXPC
  164.     putchar(c);
  165. #endif
  166. #ifdef TCAP
  167.     addch(c);
  168. #endif
  169. }
  170.  
  171. windrefresh()
  172. {
  173. #ifdef TCAP
  174.     refresh();
  175. #endif
  176. }
  177.  
  178. beep()
  179. {
  180. #ifdef ATARI
  181.     Cconout('\007');
  182. #else
  183.     putchar('\007');
  184. #endif
  185. }
  186.